<?php 
	include('lib/data_acces.php');
	include('lib/mysql.php');
	error_reporting(E_ERROR );
	$login='';
	$passw='';
	$login=$_POST['login'];
	$passw=$_POST['passw'];	
	if( $login== "" or $passw==""){
		header('location: index.php?error=1');
	}
	$user = new mydb($data_acces['host'], $data_acces['user'], $data_acces['pass'], $data_acces['db']);
	$sql="SELECT
			`usuario`.`id_user`,
			`usuario`.`nombre_usu`,
			`usuario`.`apellido_usu`,
			`usuario`.`ci_usu`,
			`usuario`.`tipo_usu`
			FROM
			`usuario`
			WHERE
			`usuario`.`login_usu` =  '".$login."' AND
			`usuario`.`pass_usu` =  '".$passw."' AND
			`usuario`.`activo_usu` =  '1'";
	$user->db_query($sql);
	$user->db_next();
	$user_list= $user->row_object;
	$id_usu=$user_list->id_user;
	$nombre_usu=$user_list->nombre_usu;
	$apellido_usu=$user_list->apellido_usu;
	$ci_usu=$user_list->ci_usu;
	$tipo_usu=$user_list->tipo_usu;
	//echo mysql_error();
	$user->db_close();
	//user_aplicat content the aplication's id, which our uses to diferences the way of entry
	if($id_usu!="" or $id_usu != NULL){
		$user_type=1;
		session_start();
		$_SESSION['id_user']=$id_usu;
		$_SESSION['user_name']=$nombre_usu;
		$_SESSION['user_lastname']=$apellido_usu;
		$_SESSION['user_ci']=$ci_usu;
		$_SESSION['user_type']=$tipo_usu;
		
		session_register('id_user','user_name','user_lastname','user_ci','user_type');
		if($tipo_usu == 1){
			header('Location: '.$data_acces['home'].'index.php');
			//echo "ups1";
		}
		/*else{ 
			header('Location: ');
		}*/
	}
	else{
		header('location: '.$data_acces['home_site'].'index.php?error=2');
		//echo "ups";
	}
	
?>